package com.guestmanage.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.guestmanage.bean.RdgionYu2;
import com.guestmanage.bean.SpRecvLis;
import com.guestmanage.service.SpRecvLisService;
import com.guestmanage.servlet.util.BaseAction;
import com.guestmanage.servlet.util.SpNameCode;

public class SpRecvLisUpdateServlet extends HttpServlet{

	private static final long serialVersionUID = -5248447577888520639L;
	
	private SpRecvLisService srlSer=SpRecvLisService.getInsetance();

	public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException ,IOException{
		BaseAction base=new BaseAction(request,response);
		
		int hourNum=base.getParameterInt("hourNum");
		
		RdgionYu2 rd2=srlSer.findByCity((String)base.getSessionAttribute("city"));
		List<SpRecvLis> srl_list=srlSer.getSpRecvLis(rd2.getTeleid(), hourNum);
		
		SpNameCode cpNameCode=new SpNameCode();
		
		base.setAttribute("cpNameCode", cpNameCode);
		base.setAttribute("srl_list", srl_list);
		base.setAttribute("hourNum", hourNum);
		base.forward("guestManage/monitor/spRecvLisUpdate.jsp");
	}
	
	public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException ,IOException{
		BaseAction base=new BaseAction(request,response);
		
//		int id=base.getParameterInt("id");
//		int hourNum=base.getParameterInt("hourNum");
//		int recvCount=base.getParameterInt("recvCount");
//		
//		boolean oo=srlSer.update(recvCount,hourNum, id);
		
		int hudaCount=base.getParameterInt("hudaCount");
		int genyuanCount=base.getParameterInt("genyuanCount");
		int dongliangCount=base.getParameterInt("dongliangCount");
		int xinlangCount=base.getParameterInt("xinlangCount");
		int xunyiCount=base.getParameterInt("xunyiCount");
		int jmhwCount=base.getParameterInt("jmhwCount");
		int yifanCount=base.getParameterInt("yifanCount");
		int wubileCount=base.getParameterInt("wubileCount");
		
		int hourNum=base.getParameterInt("hourNum");
		
		SpNameCode spnamecode=new SpNameCode();
		
		RdgionYu2 rd2=srlSer.findByCity((String)base.getSessionAttribute("city"));
		List<SpRecvLis> srl_list=srlSer.getSpRecvLis(rd2.getTeleid(), hourNum);
		for(SpRecvLis srl:srl_list){
			if(spnamecode.getHU_DA().equals(srl.getSpNameCode()))
				srl.setRecvCount(hudaCount);
			if(spnamecode.getDONG_LIANG().equals(srl.getSpNameCode()))
				srl.setRecvCount(dongliangCount);
			if(spnamecode.getGEN_YUAN().equals(srl.getSpNameCode()))
				srl.setRecvCount(genyuanCount);
			if(spnamecode.getJIANG_MEN_HAN_WEI().equals(srl.getSpNameCode()))
				srl.setRecvCount(jmhwCount);
			if(spnamecode.getXIN_LANG().equals(srl.getSpNameCode()))
				srl.setRecvCount(xinlangCount);
			if(spnamecode.getXUN_YI().equals(srl.getSpNameCode()))
				srl.setRecvCount(xunyiCount);
			if(spnamecode.getYI_FAN().equals(srl.getSpNameCode()))
				srl.setRecvCount(yifanCount);
			if(spnamecode.getWU_BI_LE().equals(srl.getSpNameCode()))
				srl.setRecvCount(wubileCount);
			
			srlSer.update(srl.getRecvCount(), hourNum, srl.getId());
		}
		
		
		base.printWriter("true");
	}
}
